package com.jzcn.admin.controller.logs;

import com.jzcn.admin.base.BaseController;
import com.jzcn.common.dto.log.LogListDTO;
import com.jzcn.common.dto.log.LoginLogDTO;
import com.jzcn.common.dto.log.SearchLogDTO;
import com.jzcn.common.dto.log.SearchLoginLogDTO;
import com.jzcn.common.response.ResponseResult;
import com.jzcn.service.SysLogService;
import com.jzcn.service.SysLoginLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(value = "Log", tags = "日志管理")
@RequestMapping("/api/logs")
public class LogController extends BaseController {

    @Resource
    SysLogService sysLogService;

    @Resource
    SysLoginLogService sysLoginLogService;

    @ApiOperation("日志列表")
    @GetMapping("/page")
    @RequiresPermissions("logs:action:list")
    public ResponseResult<List<LogListDTO>> list(SearchLogDTO searchLogDTO) {
        return ResponseResult.success(sysLogService.listPage(searchLogDTO));
    }

    @ApiOperation("登录日志列表")
    @GetMapping("/login/page")
    @RequiresPermissions("logs:login:list")
    public ResponseResult<List<LoginLogDTO>> loginList(SearchLoginLogDTO query) {
        return ResponseResult.success(sysLoginLogService.listPage(query));
    }
}
